package com.qianfeng.openapi.web.master.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.qianfeng.openapi.web.master.dto.TableData;
import com.qianfeng.openapi.web.master.entity.ApiMapping;
import com.qianfeng.openapi.web.master.service.ApiMappingService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:路由模块
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/12/30
 * @Time: 下午10:35
 */
@RestController
public class GatewayController {

    @Resource
    private ApiMappingService apiMappingService;



    ///?limit=10&offset=0&gatewayApiName=&state=
    @RequestMapping("/gateway/mapping/list")
    public TableData gatewayTableList(String gatewayApiName, Integer state, int offset, int limit){

        return  apiMappingService.apiMappingTableList(gatewayApiName,state,offset,limit);
    }

    /**
     * 新增路由信息（api映射关系）
     * @param apiMapping
     * @return
     */
    @RequestMapping("/gateway/mapping/add")
    public   R  add(@RequestBody ApiMapping apiMapping){

            return  apiMappingService.addApiMapping(apiMapping);
    }

    //[11,22,33] json数组
    @RequestMapping(value = "/gateway/mapping/del")
    public  R deleteGateway(@RequestBody List<Integer> ids){
        return  apiMappingService.batchDelete(ids);
    }


    @RequestMapping("/gateway/mapping/info")
    public  R  apiMappingInfo(int id){
        return  apiMappingService.apiMappingInfo(id);
    }

    /**
     * 修改路由信息（api映射关系）
     * @param apiMapping
     * @return
     */
    @RequestMapping("/gateway/mapping/update")
    public   R  update(@RequestBody ApiMapping apiMapping){

        return  apiMappingService.updateApiMapping(apiMapping);
    }



}
